﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Daemon.Model
{
	public partial class AdminUser
	{
		[NotMapped]
		private List<int> _roleIds;

		[NotMapped]
		public List<int> RoleIds
		{
			get
			{
				return _roleIds ?? (_roleIds = UserRoles?.Select(i => i.Id)?.ToList());
			}

			set
			{
				_roleIds = value;
			}
		}

		public List<UserRole> UserRoles { get; set; }

		[NotMapped]
		public List<AdminRole> Role { get; set; }

		[NotMapped]
		public string UserType { get; set; }

		[NotMapped]
		public List<AdminRole> Roles { get; set; }

		public AdminUser ToSimple()
		{
			return new AdminUser
			{
				Id = Id,
				IsAdmin = IsAdmin,
				UserName = UserName,
				Avatar = Avatar,
				RoleIds = UserRoles?.Select(i => i.Id).ToList() ?? new List<int>(),
			};
		}
	}
}
